package com.qf.j2112.controller;

import com.qf.j2112.anno.JWTAnno;
import com.qf.j2112.po.Address;
import com.qf.j2112.po.SysEmp;
import com.qf.j2112.service.AddressService;
import com.qf.j2112.utils.AddressUtil;
import com.qf.j2112.utils.JwtUtil;
import com.qf.j2112.vo.ActionResultVO;
import com.qf.j2112.vo.ClientActionResultVo;
import com.qf.j2112.vo.ClientAddressVo;
import com.qf.j2112.vo.ClientCartVo;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class AddressController {

    @Resource
    private AddressService addressService;
    //获取全部取票地点
    @JWTAnno(name = "获取全部取票地点")
    @PostMapping("/getAddress")
    public ClientActionResultVo getAddrList(){
        ClientActionResultVo vo=null;
        List<Address> addrList = addressService.findAll();
        List<ClientAddressVo> addressVos = new ArrayList<>();
        for (Address address : addrList) {
            ClientAddressVo addressVo = AddressUtil.addressVo(address);
            addressVos.add(addressVo);
        }
        if (!ObjectUtils.isEmpty(addrList)){
            vo=new ClientActionResultVo(200,"查询取票地点成功",addressVos);
        }else {
            vo=new ClientActionResultVo(-200,"查询取票地点失败",null);
        }
        return vo;
    }
}
